package bdcin.servlet.actions.documento;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bdcin.classesbasicas.Dissertacao;
import bdcin.classesbasicas.Documento;
import bdcin.classesbasicas.TG;
import bdcin.classesbasicas.Tese;
import bdcin.fachada.BDCInFactory;
import bdcin.fachada.IBDCIn;
import bdcin.servlet.actions.Action;

public class ExibirDocumentoRemoverAction extends Action {
	
	@Override
	public void executar(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		IBDCIn facade = BDCInFactory.getFacade();
		String id = request.getParameter("id");
		
		Documento documento=null;
		try {
			documento = facade.buscarDocumento(Long.valueOf(id));
		
		} catch (Exception e) {
			request.setAttribute("mensagem", e.getMessage());
			request.getRequestDispatcher("mensagem.jsp").forward(request, response);
		}
		
		if(documento instanceof TG){
			request.setAttribute("documento",documento);
			request.getRequestDispatcher("./Controlador?action=tg.TGAction&nomeJSP=removerTG").forward(request, response);
			
		}
		else if (documento instanceof Dissertacao){
			request.setAttribute("documento",documento);
			request.getRequestDispatcher("./Controlador?action=dissertacao.DissertacaoAction&nomeJSP=removerDissertacao").forward(request, response);		
		}
		else if(documento instanceof Tese){
			request.setAttribute("documento",documento);
			request.getRequestDispatcher("./Controlador?action=tese.TeseAction&nomeJSP=removerTese").forward(request, response);
			
		}
		else{
			request.setAttribute("mensagem", "Este documento ja esta excluido!");
			request.getRequestDispatcher("mensagem.jsp").forward(request, response);
		}

	}
}
